package com.lb.shopguide.util.lb;

import com.blankj.utilcode.util.LogUtils;
import com.lb.shopguide.constants.AppConstant;
import com.lb.shopguide.entity.goods.GoodsDetailBean;
import com.lb.shopguide.entity.goods.SkuBean;
import com.lb.shopguide.entity.order.GoodsInOrderBean;
import com.lb.shopguide.entity.recommend.RecSkuBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by kang on 2017/6/16.
 */

public class BizGoodsUtil {

    public static List<Map<String, String>> getSizeAndColorInDialog(ArrayList<SkuBean> input) {
        List<Map<String, String>> result = new ArrayList<>();
        Map<String, String> mapSize = new HashMap<>();
        Map<String, String> mapColor = new HashMap<>();
        for (int i = 0; i < input.size(); i++) {
            SkuBean sku = input.get(i);
            mapSize.put(sku.getSize(), sku.getSize());
            mapColor.put(sku.getColor(), sku.getColor());
        }
        result.add(mapSize);
        result.add(mapColor);
        return result;
    }

    public static List<Map<String, String>> getSpec12InDialog(ArrayList<RecSkuBean> input) {
        List<Map<String, String>> result = new ArrayList<>();
        Map<String, String> mapSize = new HashMap<>();
        Map<String, String> mapColor = new HashMap<>();
        for (int i = 0; i < input.size(); i++) {
            RecSkuBean sku = input.get(i);
            LogUtils.dTag(AppConstant.LOG_TAG_KEY, sku.getSkuPicUrl());
            mapSize.put(sku.getSpecAttr1(), sku.getSpecAttr1());
            mapColor.put(sku.getSpecAttr2(), sku.getSpecAttr2());
        }
        result.add(mapSize);
        result.add(mapColor);
        return result;
    }

    public static Map<String, List<SkuBean>> getSizeAndColorInDetail(ArrayList<SkuBean> input) {
        Map<String, List<SkuBean>> result = new HashMap<>();
        for (SkuBean skuBean : input) {
            if (result.containsKey(skuBean.getColor())) {
                result.get(skuBean.getColor()).add(skuBean);
            } else {
                List<SkuBean> list = new ArrayList<>();
                list.add(skuBean);
                result.put(skuBean.getColor(), list);
            }
        }
        return result;
    }

    public static int getTotalSum(List<GoodsInOrderBean> list) {
        int total = 0;
        for (GoodsInOrderBean goodsInOrderBean : list) {
            total += goodsInOrderBean.getProductSum();
        }
        return total;
    }

    public static SkuBean getCurSkuBean(String sizeCode, String colorCode, ArrayList<SkuBean> input) {
        for (int i = 0; i < input.size(); i++) {
            SkuBean sku = input.get(i);
            if (sku.getColor().equals(colorCode) && sku.getSize().equals(sizeCode)) {
                return sku;
            }
        }
        return null;
    }

    public static RecSkuBean getCurRecSkuBean(String spec1, String spec2, ArrayList<RecSkuBean> input) {
        for (int i = 0; i < input.size(); i++) {
            RecSkuBean sku = input.get(i);
            if (sku.getSpecAttr1().equals(spec1) && sku.getSpecAttr2().equals(spec2)) {
                return sku;
            }
        }
        return null;
    }

    public static String getTotalPrice(List<GoodsDetailBean> list) {
        String totalPrice = "0.0";
        for (GoodsDetailBean goodsDetailBean : list) {
            String price;
            price = "" + goodsDetailBean.getCurSkuBean().getDiscountPrice();
            totalPrice = "" + MathDecimalUtil.add(totalPrice, "" + MathDecimalUtil.mul(price, "" + goodsDetailBean.getSum()));
        }
        return totalPrice;
    }

    public static String getTotalDiscount(List<GoodsDetailBean> list) {
        String totalPrice = "0.0";
        for (GoodsDetailBean goodsDetailBean : list) {
            totalPrice = "" + MathDecimalUtil.add(totalPrice, "" + MathDecimalUtil.mul("" + MathDecimalUtil.sub("" + goodsDetailBean.getCurSkuBean().getPrice(), "" + goodsDetailBean.getCurSkuBean().getDiscountPrice()), "" + goodsDetailBean.getSum()));
        }
        return totalPrice;
    }


    public static ArrayList<GoodsDetailBean> getSelectedList(ArrayList<GoodsDetailBean> list) {
        ArrayList<GoodsDetailBean> selectedList = new ArrayList<>();
        for (GoodsDetailBean bean : list) {
            if (bean.isChecked()) {
                selectedList.add(bean);
            }
        }
        return selectedList;
    }

}
